package com.hand.wfive.adapter;

import android.annotation.SuppressLint;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hand.wfive.R;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class LoginMineAdapter extends BaseQuickAdapter<Integer, BaseViewHolder> {

    private int mMsgNum = 0;

    public LoginMineAdapter(@Nullable List<Integer> data) {
        super(R.layout.login_item_mine, data);
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, Integer integer) {
        baseViewHolder.setImageResource(R.id.iv_item, integer);
        TextView textView = baseViewHolder.getView(R.id.tv_item);
        if (integer == R.mipmap.icon_set_online_server) {
            if (mMsgNum > 0) {
                textView.setVisibility(View.VISIBLE);
                textView.setText(mMsgNum > 99 ? "99+" : mMsgNum + "");
            } else {
                textView.setVisibility(View.GONE);
            }
        } else {
            textView.setVisibility(View.GONE);
        }
    }

    public void updateMsgNum(int num) {
        if (mMsgNum == num) return;
        this.mMsgNum = num;
        notifyItemChanged(getItemPosition(R.mipmap.icon_set_online_server));
    }
}
